/*
 * @Description:
 * @Author: fhw
 * @Date: 2023-02-27 21:49:39
 */
import {
  Controller,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import multer = require('multer');
import { ApiOperation, ApiTags } from '@nestjs/swagger';

@Controller('upload')
@ApiTags('图片上传')
// @ApiBearerAuth() // Swagger 的 JWT 验证
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  /**
   * 上传图片到 本地 和 oss
   * @param body
   */
  @Post('/uploadOSS')
  @UseInterceptors(
    FileInterceptor('file', {
      storage: multer.diskStorage({
        // 开启储存本地public
        // destination: (req, file, cb) => {
        //   cb(null, join(__dirname,"../../public"));
        // },
        filename: (req, file, cb) => {
          cb(null, file.originalname);
        },
      }),
    }),
  )
  @ApiOperation({ summary: 'oss图片上传', operationId: 'uploadOSS' })
  async uploadOSS(@UploadedFile() file: any): Promise<any> {
    return await this.uploadService.uploadImage(file);
  }
}
